<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>屋面找坡厚度计算器</title>
    <style>
        :root {
            --primary: #2196F3;
            --primary-light: #BBDEFB;
            --primary-dark: #1976D2;
            --text: #212121;
            --text-light: #757575;
            --bg: #F5F9FF;
            --card: #FFFFFF;
            --border: #E0E0E0;
        }
        
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }
        
        body {
            background-color: var(--bg);
            color: var(--text);
            line-height: 1.6;
            padding: 20px;
            min-height: 100vh;
        }
        
        .container {
            max-width: 500px;
            margin: 0 auto;
            background: var(--card);
            border-radius: 16px;
            box-shadow: 0 8px 30px rgba(33, 150, 243, 0.15);
            overflow: hidden;
        }
        
        .header {
            background: linear-gradient(135deg, var(--primary), var(--primary-dark));
            color: white;
            padding: 25px 20px;
            text-align: center;
        }
        
        h1 {
            font-weight: 600;
            font-size: 1.8rem;
            margin-bottom: 8px;
        }
        
        .subtitle {
            opacity: 0.9;
            font-weight: 300;
            font-size: 1rem;
        }
        
        .content {
            padding: 25px;
        }
        
        .input-group {
            margin-bottom: 22px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: var(--text);
            font-size: 1rem;
        }
        
        .input-wrapper {
            position: relative;
            display: flex;
            align-items: center;
        }
        
        input {
            flex: 1;
            padding: 14px 15px;
            border: 2px solid var(--border);
            border-radius: 10px;
            font-size: 1rem;
            transition: all 0.3s ease;
            background: #fafafa;
        }
        
        input:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.2);
        }
        
        .unit {
            position: absolute;
            right: 15px;
            color: var(--text-light);
            font-size: 0.9rem;
        }
        
        .btn-calculate {
            width: 100%;
            padding: 16px;
            background: var(--primary);
            color: white;
            border: none;
            border-radius: 10px;
            font-size: 1.1rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 10px rgba(33, 150, 243, 0.3);
        }
        
        .btn-calculate:hover {
            background: var(--primary-dark);
            transform: translateY(-2px);
            box-shadow: 0 6px 15px rgba(33, 150, 243, 0.4);
        }
        
        .btn-calculate:active {
            transform: translateY(0);
        }
        
        .result-container {
            margin-top: 30px;
            padding: 20px;
            background: var(--primary-light);
            border-radius: 12px;
            display: none;
        }
        
        .result-title {
            font-weight: 600;
            margin-bottom: 15px;
            color: var(--primary-dark);
            font-size: 1.2rem;
            display: flex;
            align-items: center;
        }
        
        .result-title i {
            margin-right: 10px;
            font-size: 1.5rem;
        }
        
        .formula {
            background: rgba(255, 255, 255, 0.7);
            padding: 15px;
            border-radius: 8px;
            margin-bottom: 20px;
            font-family: monospace;
            font-size: 1.1rem;
        }
        
        .result-value {
            display: flex;
            justify-content: space-between;
            margin-top: 15px;
            padding-top: 15px;
            border-top: 1px dashed rgba(25, 118, 210, 0.3);
        }
        
        .unit-result {
            text-align: center;
            flex: 1;
        }
        
        .unit-label {
            font-size: 0.9rem;
            color: var(--text-light);
            margin-bottom: 5px;
        }
        
        .unit-number {
            font-size: 1.8rem;
            font-weight: 700;
            color: var(--primary-dark);
        }
        
        @media (max-width: 480px) {
            body {
                padding: 10px;
            }
            
            .container {
                border-radius: 12px;
            }
            
            .header {
                padding: 20px 15px;
            }
            
            h1 {
                font-size: 1.5rem;
            }
            
            .content {
                padding: 20px 15px;
            }
            
            input {
                padding: 12px 15px;
            }
            
            .btn-calculate {
                padding: 14px;
            }
            
            .result-container {
                padding: 15px;
            }
            
            .unit-number {
                font-size: 1.5rem;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>屋面找坡厚度计算器</h1>
            <div class="subtitle">精准计算屋面找坡平均厚度</div>
        </div>
        
        <div class="content">
            <div class="input-group">
                <label for="length">找坡长度</label>
                <div class="input-wrapper">
                    <input type="number" id="length" step="0.1" value="10" placeholder="输入长度">
                    <div class="unit">米(m)</div>
                </div>
            </div>
            
            <div class="input-group">
                <label for="slope">找坡系数</label>
                <div class="input-wrapper">
                    <input type="number" id="slope" step="0.1" value="2" placeholder="输入坡度">
                    <div class="unit">%(百分比)</div>
                </div>
            </div>
            
            <div class="input-group">
                <label for="minThickness">最薄处厚度</label>
                <div class="input-wrapper">
                    <input type="number" id="minThickness" step="0.001" value="0.02" placeholder="输入厚度">
                    <div class="unit">米(m)</div>
                </div>
            </div>
            
            <button class="btn-calculate" onclick="calculate()">计算平均厚度</button>
            
            <div class="result-container" id="resultContainer">
                <div class="result-title">
                    <i>📐</i> 计算结果 
                </div>
                <div class="formula" id="formulaDisplay"></div>
                <div class="result-value">
                    <div class="unit-result">
                        <div class="unit-label">米(m)</div>
                        <div class="unit-number" id="resultM"></div>
                    </div>
                    <div class="unit-result">
                        <div class="unit-label">毫米(mm)</div>
                        <div class="unit-number" id="resultMM"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
 
    <script>
        function calculate() {
            // 获取输入值 
            const length = parseFloat(document.getElementById('length').value); 
            const slope = parseFloat(document.getElementById('slope').value)  / 100;
            const minThickness = parseFloat(document.getElementById('minThickness').value); 
 
            // 验证输入 
            if (isNaN(length) || isNaN(slope) || isNaN(minThickness)) {
                alert("请输入有效数值");
                return;
            }
 
            // 执行计算 
            const H_m = (length * slope) / 2 + minThickness;
            const H_mm = H_m * 1000;  // 转换为毫米 
            
            // 计算过程展示 
            const slopePercent = slope * 100;
            const thicknessIncrease = (length * slope / 2).toFixed(3);
            const minThicknessFormatted = minThickness.toFixed(3); 
            
            document.getElementById('formulaDisplay').innerHTML  = 
                `H = (L × i)/2 + a = (${length} × ${slopePercent}%)/2 + ${minThicknessFormatted}<br>` +
                `= (${(length * slope).toFixed(3)})/2 + ${minThicknessFormatted}<br>` +
                `= ${thicknessIncrease} + ${minThicknessFormatted}`;
            
            // 显示结果 
            document.getElementById('resultM').textContent  = H_m.toFixed(3); 
            document.getElementById('resultMM').textContent  = H_mm.toFixed(1); 
            
            // 显示结果容器 
            document.getElementById('resultContainer').style.display  = 'block';
        }
        
        // 初始计算 
        window.onload  = calculate;
    </script>
</body>
</html>